/*
 * ManagedBean.java
 *
 * Created on May 15, 2007, 11:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.vce.web;

import com.vce.election.Election;
import com.vce.SecurityManager;
import java.io.Serializable;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.appfuse.webapp.util.FacesUtils;
/**
 *
 * @author lruiz
 */
public class ManagedBean implements Serializable {

    private transient Election election;
    private transient SecurityManager securityManager;

    /** Creates a new instance of WebBean */
    public ManagedBean() {
    }

    public Election getElection() {
        if (election == null) {
            election = (Election) lookup("election");
        }
        return election;
    }

    public SecurityManager getSecurityManager() {
        if (securityManager == null) {
            securityManager = (SecurityManager) lookup("securityManager");
        }
        return securityManager;
    }

    public Map<String, String> getParameterMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    }

    public Map<String, String[]> getParameterValuesMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap();
    }

    public Map getRequestMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
    }

    public Map getSessionMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
    }

    public Map getApplicationMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
    }

    public void addErrorMessage(String message) {
        FacesUtils.addErrorMessage(message);
    }

    public void addInfoMessage(String message) {
        FacesUtils.addInfoMessage(message);
    }

    public Object lookup(String name) {
        return FacesUtils.getManagedBean(name);
    }

    public void reset(String name) {
        ((ManagedBean) lookup(name)).reset();
    }

    public void dispose() {
    }

    public String startup() {
        return "fail";
    }

    public String startup(ActionEvent e) {
        return startup();
    }

    public String cancel() {
        return "cancel";
    }

    public void reset() {
    }
}
